﻿using MediatR;
using MS.BasicData.Infrastructure;
using MS.BasicData.Infrastructure.IBaseRepository;

namespace MS.BasicData.Read.API.Applications.Roles
{
    public class CreateRoleRequestHandler : IRequestHandler<CreateRoleRequestModel, ApiRestult>
    {
        /// <summary>
        /// 角色仓储
        /// </summary>
        private readonly IRoleBaseRepository _roleRepository;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="roleRepository"></param>
        public CreateRoleRequestHandler(IRoleBaseRepository roleRepository)
        {
            _roleRepository = roleRepository;
        }
        public async Task<ApiRestult> Handle(CreateRoleRequestModel request, CancellationToken cancellationToken)
        {
              ApiRestult restult = new ApiRestult();

            restult.isSuc = true;
            restult.Code = Restult.Success;
            restult.Message = "创建角色成功";

            MS.BasicData.Domain.Roles role = new MS.BasicData.Domain.Roles
            {
                RoleName = request.RoleName,
                Description = request.Description,
                IsDeleted = false
            };
            await _roleRepository.InsertAsync(role);
            return await Task.FromResult(restult);
        }

        
    }



    public class CreateRoleRequestModel : IRequest<ApiRestult>
    {
        /// <summary>
        /// 角色名称
        /// </summary>
        public string RoleName { get; set; } = string.Empty;

        /// <summary>
        /// 角色描述
        /// </summary>
        public string Description { get; set; } = string.Empty;
    }
}
